<template>
<div>
<div style="padding:0px 0px 20px 0px">
<el-row>
  <el-col :span="12"><div class="grid-content bg-purple"><el-input
    placeholder="请输入内容"
    prefix-icon="el-icon-search"
    v-model="input2">
  </el-input></div></el-col>
  <el-col :span="12"><div class="grid-content bg-purple-light" style="text-align:right;">
  批量删除 | 批量停用
  <el-button type="warning">警告按钮</el-button></div></el-col>
</el-row>
</div>
<div>
</div>
  <el-table
    class="tableBox"
    ref="multipleTable"
    :data="tableData"
    tooltip-effect="dark"
    style="width: 100%;solid 2px #2e354a"
    @selection-change="handleSelectionChange">
    <el-table-column
      type="selection"
      width="55">
    </el-table-column>
    <el-table-column
      label="日期"
      width="120">
      <template slot-scope="scope">{{ scope.row.create_time }}</template>
    </el-table-column>
    <el-table-column
      prop="name"
      label="姓名"
      width="120">
    </el-table-column>
    <el-table-column width="120">
    <template slot-scope="scope"><el-button @click='getresource(scope.row.id)'>配制资源</el-button></template>
    </el-table-column>
  </el-table>
  <div style="margin-top: 20px">
    <el-button @click="toggleSelection([tableData[1], tableData[2]])">切换第二、第三行的选中状态</el-button>
    <el-button @click="toggleSelection()">取消选择</el-button>
  </div>

<el-dialog
  title="提示"
  :visible.sync="dialogVisible"
  width="30%"
>
  <el-transfer v-model="value" :data="data"></el-transfer>

  <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="setresource()">确 定</el-button>
  </span>
</el-dialog>



  </div>
</template>

<script>
  export default {
    data() {
      return {
        tableData: [],
        multipleSelection: [],
        dialogVisible:false,
        value:[],
        data:[],
        roleid:0
      }
    },

    methods: {
      toggleSelection(rows) {
        if (rows) {
          rows.forEach(row => {
            this.$refs.multipleTable.toggleRowSelection(row);
          });
        } else {
          this.$refs.multipleTable.clearSelection();
        }
      },
      //获取角色列表
      getrolelist(page){
        this.axios.get('rbac/promitions/getrolelist?page='+page+"&page_size=10").then(res=>{
          this.tableData = res.data.data.items
        })
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      getresource(roleid){
        this.roleid = roleid
        //获取二级资源列表
        this.axios.get('rbac/promitions/gettworesource').then(res=>{
          this.data = res.data.data.items
          
        })
        //获取此角色已经配制的资源
        this.axios.get("rbac/promitions/getRoleResource?roleid="+roleid).then(res=>{
          console.log(res)
          this.value = res.data.data.items
        })
        this.dialogVisible = true
       
      },
      //配制新的资源
      setresource(){
         this.axios.post("rbac/promitions/setResource?roleid="+this.roleid+"&idlist="+this.value).then(res=>{
          if(res.data.code == '1001'){
            alert(res.data.message)
          }else{
             this.dialogVisible = false
             this.roleid=0
          }
         
        })

      }
      // del(){
      //   this.axios.get("rbac/promitions/del_resource?ids="+this.value).then(res=>{
      //     console.log(res)
      //   })
      // }
    },
    mounted() {
      this.getrolelist(1)
      // this.del()
    },
  }
</script>
<style scoped>
.tableBox{
  border:solid 2px #f3f4f7;
}
</style>